package org.bigmarketapi.projectreview.DesingMode.strategyMode.factory;

import lombok.extern.slf4j.Slf4j;
import org.bigmarketapi.projectreview.DesingMode.strategyMode.ILogicChain;
import org.springframework.stereotype.Service;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

/**
 * @BelongsProject: ProjectReview
 * @BelongsPackage: org.bigmarketapi.projectreview.DesingMode.strategyMode
 * @Author: dujiaqi
 * @CreateTime: 2024-08-13  14:41
 * @Description: TODO 工厂组合各个工厂模式
 * @Version: 1.0
 */
@Service
@Slf4j
public class logicFactory {
    Map<String, ILogicChain> chainGroup=new ConcurrentHashMap<>();

    public logicFactory(Map<String, ILogicChain> chainGroup) {
        this.chainGroup = chainGroup;
    }
    public ILogicChain  chainFactory(){
        String str="first,second,third";
        final String[] split = str.split(",");
         ILogicChain firstLogic = chainGroup.get(split[0]);
         //需要“指针”接着往下移动,用针线串联起来
        ILogicChain current=firstLogic;
        for (int i = 1; i < split.length; i++) {
            final ILogicChain chain = chainGroup.get(split[i]);
            if (chain!=null){
                current=current.appendNext(chain);
            }
        }
        return firstLogic;
    }
}
